package cn.com.bluemoon.daps.webhook.api.factory;

import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.webhook.api.RemoteWebhookService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 标准服务降级处理
 *
 * @author Jarod Kong
 */
@Component
public class RemoteWebhookFallbackFactory implements FallbackFactory<RemoteWebhookService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteWebhookFallbackFactory.class);

    @Override
    public RemoteWebhookService create(Throwable throwable) {
        log.error("webhook服务调用失败:{}", throwable.getMessage());
        return new RemoteWebhookService() {

            @Override
            public ResultBean<String> ok(Map<String, Object> map, Integer type, String gitRefRegex) {
                return ResultBean.error("发送数据到webhook失败");
            }

        };
    }
}
